/*
 * @lc app=leetcode.cn id=349 lang=csharp
 *
 * [349] 两个数组的交集
 */

// @lc code=start
public class Solution {
    public int[] Intersection(int[] nums1, int[] nums2) {
        HashSet<int> set = new();
        
        for(int i = 0; i < nums1.Length; ++i)
        {
            set.Add(nums1[i]);
        }
        
        int ix = -1;
        HashSet<int> ansSet = new();
        for(int i = 0; i < nums2.Length; ++i)
        {
            if(set.Contains(nums2[i]))
            {
                set.Remove(nums2[i]);
                ansSet.Add(nums2[i]);
            }
        }
        return ansSet.ToArray();
    }
}
// @lc code=end

